package com.shitou.shitoumember.controller;

import java.util.Arrays;
import java.util.Map;

import com.shitou.shitoucommons.annotation.CheckUserLogin;
import com.shitou.shitoumember.entity.GrowthChangeHistoryEntity;
import com.shitou.shitoumember.vo.CollectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.shitou.shitoumember.entity.MemberCollectSpuEntity;
import com.shitou.shitoumember.service.MemberCollectSpuService;
import com.shitou.shitoucommons.utils.PageUtils;
import com.shitou.shitoucommons.utils.RespBean;



/**
 * 会员收藏的商品
 *
 * @author shitouren
 * @email 3076767823@qq.com
 * @date 2023-03-28 16:52:06
 */
@RestController
@RequestMapping("shitoumember/membercollectspu")
public class MemberCollectSpuController {
    @Autowired
    private MemberCollectSpuService memberCollectSpuService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public RespBean list(@RequestParam Map<String, Object> params){
        PageUtils page = memberCollectSpuService.queryPage(params);

        return RespBean.success().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    public RespBean info(@PathVariable("attrId") Long attrId){
        MemberCollectSpuEntity attr = memberCollectSpuService.getById(attrId);

        return RespBean.success().put("attr", attr);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public RespBean save(@RequestBody MemberCollectSpuEntity attr){
        memberCollectSpuService.save(attr);

        return RespBean.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public RespBean update(@RequestBody MemberCollectSpuEntity attr){
        memberCollectSpuService.updateById(attr);

        return RespBean.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public RespBean delete(@RequestBody Long[] attrIds){
        memberCollectSpuService.removeByIds(Arrays.asList(attrIds));

        return RespBean.success();
    }


    /**
     * 创建收藏
     * @param collectVo
     * @return
     */
    @ApiOperation(value = "创建用户的商品收藏, 需要登录校验", response = RespBean.class)
    @CheckUserLogin
    @PostMapping("/createCollect")
    public RespBean createCollect(@RequestBody CollectVo collectVo){
        return memberCollectSpuService.crateCollect(collectVo);
    }


    /**
     * 真实删除，删除收藏品
     * @param memberId
     * @param id
     * @return
     */
    @ApiOperation(value = "删除用户收藏的商品，采用真实删除, 需要登录校验")
    @CheckUserLogin
    @PostMapping("/deleteCollect")
    public RespBean deleteCollect(@RequestParam long memberId, @RequestParam long id){
        return memberCollectSpuService.deleteCollect(memberId, id);
    }


    /**
     * 获取当前用户的所有收藏的商品
     * @param memberId
     * @return
     */
    @ApiOperation(value = "获取当前登录用户所有收藏的商品, 需要登录校验")
    @CheckUserLogin
    @PostMapping("/getMemberCollect")
    public RespBean getMemberCollect(@RequestParam long memberId){
        return memberCollectSpuService.getMemberCollect(memberId);
    }


    /**
     * 批量删除
     * @param memberId
     * @param idS
     * @return
     */
    @ApiOperation(value = "批量删除当前登录用户的收藏，需要登录校验")
    @CheckUserLogin
    @PostMapping("/deleteBatchCollect")
    public RespBean deleteBatchCollect(@RequestParam long memberId, @RequestParam long[] idS){
        return memberCollectSpuService.deleteBatchCollect(memberId, idS);
    }

}
